package com.airbat.prize.modules.system.controller.area;

import com.airbat.prize.common.pojo.CommonResult;
import com.airbat.prize.common.pojo.PageResult;
import com.airbat.prize.modules.system.controller.area.vo.*;
import com.airbat.prize.modules.system.convert.area.SysAreaConvert;
import com.airbat.prize.modules.system.dal.dataobject.area.SysAreaDO;
import com.airbat.prize.modules.system.service.area.SysAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.airbat.prize.common.pojo.CommonResult.success;
import static com.airbat.prize.operatelog.core.enums.OperateTypeEnum.*;

@Api(tags = "全国地区")
@RestController
@RequestMapping("/sys/area")
@Validated
public class SysAreaController {

    @Resource
    private SysAreaService areaService;

//    @PostMapping("/create")
//    @ApiOperation("创建全国地区")
//    @PreAuthorize("@ss.hasPermission('sys:area:create')")
//    public CommonResult<String> createArea(@Valid @RequestBody SysAreaCreateReqVO createReqVO) {
//        return success(areaService.createArea(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @ApiOperation("更新全国地区")
//    @PreAuthorize("@ss.hasPermission('sys:area:update')")
//    public CommonResult<Boolean> updateArea(@Valid @RequestBody SysAreaUpdateReqVO updateReqVO) {
//        areaService.updateArea(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @ApiOperation("删除全国地区")
//    @ApiImplicitParam(name = "id", value = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('sys:area:delete')")
//    public CommonResult<Boolean> deleteArea(@RequestParam("id") String id) {
//        areaService.deleteArea(id);
//        return success(true);
//    }
//
//    @GetMapping("/get")
//    @ApiOperation("获得全国地区")
//    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('sys:area:query')")
//    public CommonResult<SysAreaRespVO> getArea(@RequestParam("id") String id) {
//        SysAreaDO area = areaService.getArea(id);
//        return success(SysAreaConvert.INSTANCE.convert(area));
//    }
//
//    @GetMapping("/list")
//    @ApiOperation("获得全国地区列表")
//    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
//    @PreAuthorize("@ss.hasPermission('sys:area:query')")
//    public CommonResult<List<SysAreaRespVO>> getAreaList(@RequestParam("ids") Collection<String> ids) {
//        List<SysAreaDO> list = areaService.getAreaList(ids);
//        return success(SysAreaConvert.INSTANCE.convertList(list));
//    }

    @GetMapping("/page")
    @ApiOperation("获得全国地区分页")
    @PreAuthorize("@ss.hasPermission('sys:area:query')")
    public CommonResult<PageResult<SysAreaRespVO>> getAreaPage(@Valid SysAreaPageReqVO pageVO) {
        PageResult<SysAreaDO> pageResult = areaService.getAreaPage(pageVO);
        return success(SysAreaConvert.INSTANCE.convertPage(pageResult));
    }

//    @GetMapping("/export-excel")
//    @ApiOperation("导出全国地区 Excel")
//    @PreAuthorize("@ss.hasPermission('sys:area:export')")
//    @OperateLog(type = EXPORT)
//    public void exportAreaExcel(@Valid SysAreaExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<SysAreaDO> list = areaService.getAreaList(exportReqVO);
//        // 导出 Excel
//        List<SysAreaExcelVO> datas = SysAreaConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "全国地区.xls", "数据", SysAreaExcelVO.class, datas);
//    }

}
